package es.indra.malaga.filters;

import java.util.Locale;

import javax.faces.context.FacesContext;

import es.indra.malaga.managedBeans.LoginBean;

public class NavigationFilter {

	public NavigationFilter() {
		stablishLanguage();
	}

	private void stablishLanguage() {
		FacesContext facesContext = FacesContext.getCurrentInstance();
		if (facesContext != null) {
			LoginBean login = (LoginBean) FacesContext.getCurrentInstance()
					.getExternalContext().getSessionMap().get("loginBean");
			if (login != null) {
				if (login.getUsuario() != null
						&& login.getUsuario().getLanguage() != null) {
					Locale locale = new Locale(login.getUsuario().getLanguage());
					FacesContext.getCurrentInstance().getViewRoot()
							.setLocale(locale);
				}
			}
		}
	}

}
